<?php
// +----------------------------------------------------------------------
// | 有理想的地方，地狱都是天堂。
// +----------------------------------------------------------------------
// | Copyright @ df81.com 版权所有
// +----------------------------------------------------------------------
// | 作者: 南国老符 邮箱：1062129401@qq.com
// +----------------------------------------------------------------------

namespace app\api\model\v1;
use think\Model;
use Overtrue\Pinyin\Pinyin;

class PinyinStr extends Model{
    /**
     * 汉字转拼音
     * title 需要转成拼音的字符串
    */
    static function view($title = ''){
        $pinyin = new Pinyin();
        switch (config('global.url.pinyin_type')) {
            // 首字母
            case 'abbr':
                $urlroute = $pinyin->abbr($title);
                break;
            // 全拼
            default:
                $urlroute = $pinyin->permalink($title,'');
                break;
        }
        $urlroute = strtolower(msubstr($urlroute,0,config('global.url.length'),''));
        
        return $urlroute;
    }
}